/*********************************************************************************
 *      Copyright:  (C) 2022 xiezongyi<1764417007@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  CRC.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(12/08/22)
 *         Author:  xiezongyi <1764417007@qq.com>
 *      ChangeLog:  1, Release initial version on "12/08/22 17:56:03"
 *                 
 ********************************************************************************/
#include <stdint.h>

uint16_t crc16_maxim(char *data, uint16_t length)
{
    uint8_t i;
    uint16_t crc = 0;        // Initial value

    while(length--)
    {
        crc ^= *data++;        // crc ^= *data; data++;
        for (i = 0; i < 8; ++i)
        {
            if (crc & 1)
                crc = (crc >> 1) ^ 0xA001;        // 0xA001 = reverse 0x8005
            else
                crc = (crc >> 1);
        }
    }
    return ~crc;    // crc^0xffff
}


